<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <div>欢迎光临 vue收银系统—水果店</div>
        <tr>
            <td>苹果 {{msg}}￥，折扣《8折》</td>
        </tr>
        <div>
            <ul>
                <li>请输入你要购买的斤数 <input v-model="price" type="text"></li>
                <li><button @click="add">结账买单</button></li>
                <li>结账单: 总价:{{str}}元 折后价 {{discountRate}}元 省了{{discount}}元</li>
            </ul>
        </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                msg: 10,
                price: '', // 购买的斤数
                str: 0,
                discountRate: 0.8,
                discount: 0
            },
            computed: {

            },
            methods: {
                // 计算总价格
                add() {
                    if (this.price == '') {
                        alert('请输入购买斤数')
                    } else {
                        this.str = this.price * this.msg; // 总价
                        this.discountRate = this.str * this.discountRate; // 折后价
                        this.discount = this.str - this.discountRate;
                        this.price = '';
                    }

                    // 


                }
            }
        });
    </script>
</body>

</html>